package com.sanji.register.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.id.UUIDGenerator;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

import javax.annotation.Generated;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;
import java.util.UUID;

/**
 *  @author yangqc
 *  2017-05-14
 */
@Entity
@Table(name = "user")
public class User implements Serializable{
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "user_id")
//    @GenericGenerator( name="id" ,strategy = "uuid")
//    @GeneratedValue(strategy = GenerationType.AUTO,generator="id")
    private String id;
    @Column(name = "phone",unique = true)
    @NotEmpty(message = "* 请提供手机号码")
    private String phone;
    @Column(name = "password")
    @Length(min = 6, message = "* 密码至少六位数")
    @NotEmpty(message = "* 请输入密码")
    private String password;
    @Column(name = "name",unique = true)
    @NotEmpty(message = "* 输入用户名")
    private String name;

    @Column(name = "active")
    private int active=1;
    @ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
    private Set<Role> roles;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getActive() {
        return active;
    }

    public void setActive(int active) {
        this.active = active;
    }

    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}